import { Component } from '@angular/core';
import {BMIForm} from './vo/BMIForm';
import {ResultVo} from './vo/ResultVo';
import {BmiService} from './service/bmi.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  bmiform: BMIForm;
  resultvo: ResultVo;
  imageurl: string;

  constructor(private bmiservice: BmiService) {
    this.bmiform = new BMIForm();
    this.resultvo = new ResultVo();

  }
  getBMivalue() {
    console.log('身高' + this.bmiform.sg + '体重' + this.bmiform.tg);
    this.bmiservice.getBMIValue(this.bmiform)
      .then((data: any) => {
        this.resultvo = data;
        this.getPic();
      });
  }
  getPic() {
    switch (this.resultvo.state) {
      case'偏瘦':
        this.imageurl = '/assets/images/thin.jpg';
        break;
      case'正常':
        this.imageurl = '/assets/images/normal.jpg';
        break;
      case'过重':
        this.imageurl = '/assets/images/babyfat.jpg';
        break;
      case'肥胖':
        this.imageurl = '/assets/images/fat.jpg';
        break;
    }
  }
}
